from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2021-01-26 14:07:09.526968
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Tue, 26, Jan, 2021
Time: 14:07:13
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -45.5492
Nobs: 183.000 HQIC: -46.4878
Log likelihood: 2065.19 FPE: 3.41319e-21
AIC: -47.1276 Det(Omega_mle): 2.11448e-21
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.444256 0.142749 3.112 0.002
L1.Burgenland 0.128369 0.074737 1.718 0.086
L1.Kärnten -0.233012 0.061238 -3.805 0.000
L1.Niederösterreich 0.131558 0.172017 0.765 0.444
L1.Oberösterreich 0.211455 0.149934 1.410 0.158
L1.Salzburg 0.190557 0.079189 2.406 0.016
L1.Steiermark 0.099286 0.106840 0.929 0.353
L1.Tirol 0.162921 0.071193 2.288 0.022
L1.Vorarlberg -0.005352 0.066816 -0.080 0.936
L1.Wien -0.115977 0.143339 -0.809 0.418
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.501653 0.181563 2.763 0.006
L1.Burgenland 0.021167 0.095059 0.223 0.824
L1.Kärnten 0.370602 0.077889 4.758 0.000
L1.Niederösterreich 0.109476 0.218790 0.500 0.617
L1.Oberösterreich -0.169159 0.190703 -0.887 0.375
L1.Salzburg 0.188828 0.100721 1.875 0.061
L1.Steiermark 0.250100 0.135892 1.840 0.066
L1.Tirol 0.135450 0.090551 1.496 0.135
L1.Vorarlberg 0.177372 0.084984 2.087 0.037
L1.Wien -0.573071 0.182315 -3.143 0.002
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.290721 0.064558 4.503 0.000
L1.Burgenland 0.114436 0.033800 3.386 0.001
L1.Kärnten -0.024601 0.027695 -0.888 0.374
L1.Niederösterreich 0.067601 0.077794 0.869 0.385
L1.Oberösterreich 0.285158 0.067807 4.205 0.000
L1.Salzburg 0.006978 0.035813 0.195 0.846
L1.Steiermark -0.023292 0.048318 -0.482 0.630
L1.Tirol 0.092486 0.032197 2.873 0.004
L1.Vorarlberg 0.117088 0.030217 3.875 0.000
L1.Wien 0.078156 0.064825 1.206 0.228
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.218550 0.073653 2.967 0.003
L1.Burgenland -0.010203 0.038562 -0.265 0.791
L1.Kärnten 0.020974 0.031596 0.664 0.507
L1.Niederösterreich 0.023054 0.088755 0.260 0.795
L1.Oberösterreich 0.393226 0.077361 5.083 0.000
L1.Salzburg 0.098758 0.040859 2.417 0.016
L1.Steiermark 0.181574 0.055126 3.294 0.001
L1.Tirol 0.043713 0.036733 1.190 0.234
L1.Vorarlberg 0.092890 0.034475 2.694 0.007
L1.Wien -0.064831 0.073958 -0.877 0.381
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.539929 0.147194 3.668 0.000
L1.Burgenland 0.077373 0.077065 1.004 0.315
L1.Kärnten 0.002772 0.063145 0.044 0.965
L1.Niederösterreich -0.036971 0.177374 -0.208 0.835
L1.Oberösterreich 0.152264 0.154603 0.985 0.325
L1.Salzburg 0.054614 0.081655 0.669 0.504
L1.Steiermark 0.119137 0.110168 1.081 0.280
L1.Tirol 0.217382 0.073410 2.961 0.003
L1.Vorarlberg 0.012656 0.068896 0.184 0.854
L1.Wien -0.125749 0.147803 -0.851 0.395
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.152165 0.104639 1.454 0.146
L1.Burgenland -0.017232 0.054785 -0.315 0.753
L1.Kärnten -0.014568 0.044889 -0.325 0.746
L1.Niederösterreich 0.135773 0.126094 1.077 0.282
L1.Oberösterreich 0.394415 0.109906 3.589 0.000
L1.Salzburg -0.024389 0.058048 -0.420 0.674
L1.Steiermark -0.035324 0.078317 -0.451 0.652
L1.Tirol 0.186962 0.052186 3.583 0.000
L1.Vorarlberg 0.046798 0.048978 0.955 0.339
L1.Wien 0.182403 0.105072 1.736 0.083
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.218906 0.133851 1.635 0.102
L1.Burgenland 0.090226 0.070079 1.287 0.198
L1.Kärnten -0.047034 0.057421 -0.819 0.413
L1.Niederösterreich -0.014221 0.161295 -0.088 0.930
L1.Oberösterreich -0.107302 0.140589 -0.763 0.445
L1.Salzburg 0.030608 0.074253 0.412 0.680
L1.Steiermark 0.387163 0.100181 3.865 0.000
L1.Tirol 0.490213 0.066755 7.343 0.000
L1.Vorarlberg 0.176839 0.062651 2.823 0.005
L1.Wien -0.223979 0.134405 -1.666 0.096
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.124578 0.158392 0.787 0.432
L1.Burgenland 0.016287 0.082928 0.196 0.844
L1.Kärnten -0.106913 0.067949 -1.573 0.116
L1.Niederösterreich 0.233932 0.190868 1.226 0.220
L1.Oberösterreich 0.023027 0.166365 0.138 0.890
L1.Salzburg 0.221712 0.087867 2.523 0.012
L1.Steiermark 0.122763 0.118549 1.036 0.300
L1.Tirol 0.086545 0.078995 1.096 0.273
L1.Vorarlberg 0.024921 0.074138 0.336 0.737
L1.Wien 0.264114 0.159048 1.661 0.097
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.579004 0.085333 6.785 0.000
L1.Burgenland -0.018187 0.044677 -0.407 0.684
L1.Kärnten -0.001753 0.036607 -0.048 0.962
L1.Niederösterreich -0.033086 0.102829 -0.322 0.748
L1.Oberösterreich 0.280836 0.089628 3.133 0.002
L1.Salzburg 0.016703 0.047338 0.353 0.724
L1.Steiermark 0.013691 0.063868 0.214 0.830
L1.Tirol 0.076848 0.042558 1.806 0.071
L1.Vorarlberg 0.150780 0.039941 3.775 0.000
L1.Wien -0.061158 0.085686 -0.714 0.475
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.149740 0.002948 0.213304 0.253269 0.067389 0.059628 -0.065607 0.166557
Kärnten 0.149740 1.000000 0.021807 0.199259 0.163298 -0.112545 0.174372 0.026252 0.315995
Niederösterreich 0.002948 0.021807 1.000000 0.304566 0.081049 0.219055 0.136377 0.060488 0.363207
Oberösterreich 0.213304 0.199259 0.304566 1.000000 0.296888 0.306864 0.102546 0.080880 0.132224
Salzburg 0.253269 0.163298 0.081049 0.296888 1.000000 0.158658 0.047773 0.074972 -0.016327
Steiermark 0.067389 -0.112545 0.219055 0.306864 0.158658 1.000000 0.109617 0.092559 -0.097560
Tirol 0.059628 0.174372 0.136377 0.102546 0.047773 0.109617 1.000000 0.161291 0.146816
Vorarlberg -0.065607 0.026252 0.060488 0.080880 0.074972 0.092559 0.161291 1.000000 0.079129
Wien 0.166557 0.315995 0.363207 0.132224 -0.016327 -0.097560 0.146816 0.079129 1.000000